
<template>
  <el-upload
      class="avatar-uploader"
      action="http://localhost:8080/upload"
      :show-file-list="false"
      :on-success="handleAvatarSuccess">
    <img v-if="imageUrl" :src="imageUrl" class="avatar" />
    <el-icon v-else class="avatar-uploader-icon">上传</el-icon>
  </el-upload>
</template>

<script>
export default {
  name: "UploadView",
  data(){
    return {
      imageUrl: ''  //图片的URL
    }
  },
  methods:{
    //处理上传成功的事件
    handleAvatarSuccess(res){
      console.log('upload',res)
      if(res.code === 200){
        this.imageUrl = res.data
      }
    }
  }
}
</script>


<style scoped>
.avatar-uploader .el-upload {
  border: 1px dashed var(--el-border-color);
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  transition: var(--el-transition-duration-fast);
}

.avatar-uploader .el-upload:hover {
  border-color: var(--el-color-primary);
}

.el-icon.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 178px;
  height: 178px;
  text-align: center;
}
</style>